home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / InsideBa1994 / InsideBasic-94 / IB 94 / TextFileReader / Text File Reader.BAS
BASIC Source File  |  1993-05-05  |  1KB  |  34 lines

  1.  
  2.  
  3. LOCAL FN ReadTextFile (efID)
  4.   DIM rect.8
  5.   
  6.   fileName$ = FILES$ (_fOpen, "TEXT", , vRefNum%)
  7.   LONG IF fileName$ <> ""
  8.     OPEN "I", #1, fileName$, , vRefNum%'open file here
  9.     LONG IF SYSERROR = _noErr        'whew, no error
  10.       size% = LOF (1,1)              'get file size
  11.       LONG IF size% < 32767          'will all text fit?
  12.         hndl& = FN NEWHANDLE (size% + 2)'create handle of size
  13.         LONG IF hndl& <> 0 AND SYSERROR = _noErr'got valid handle?
  14.           osErr  = FN HLOCK(hndl&)   'lock in memory
  15.           POKE WORD [hndl&], size%   'poke length into handle
  16.           READ FILE #1, [hndl&] + 2, size%'read text file to handle
  17.           osErr = FN HUNLOCK (hndl&)'unlock text handle
  18.           EDIT FIELD #efID, &hndl&   'put text into edit field
  19.           DEF DISPOSEH (hndl&)       'release memory
  20.         XELSE
  21.           BEEP : BEEP                'can’t get handle error
  22.         END IF
  23.       XELSE
  24.         BEEP : BEEP                  'text file too large!!
  25.       END IF
  26.       CLOSE #1                       'close text file
  27.     XELSE
  28.       BEEP : BEEP                    'file open error
  29.     END IF
  30.   END IF
  31. END FN
  32.  
  33.  
  34.